#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <arpa/inet.h>
#include <error.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <pthread.h>


#define MAXSIZE 60



// block queue
typedef struct Queue{
    int rear;   //tail pointer
    int front;  //head pointer
    int element[MAXSIZE];
    int size;
}queue_t;


//thread pool
typedef struct status{
    int num;    // num of threads
    pthread_t *tids;  //threads ID
    int flag;   //0:live, 1:kill
    pthread_mutex_t lock;   //  lock of thread
    pthread_cond_t cond;    //condition variables of threads

    queue_t b_queue;
}status_t;

typedef struct User{
    char *user_name;
    char *paths;
}user_t;

int enqueue(queue_t *b_queue, int net_fd);
int dequeue(queue_t *b_queue, int *net_fd);
int init_status(status_t *pool, int num);
int init_socket(int *socket_fd, char *ip, char *port);
int add_epoll(int ep_fd, int socket_fd);
int getparameter(char *key, char *velue);
void *thread_main(void *p);
int do_worker(int net_fd);
int analyse(char *strs, int net_fd);
bool login_client(char *username, char *passward);
int shell_puts(const user_t *user);
bool registered(char *username, char *passward);
int load_file(int net_fd, char *filename);
int log_write(char *funcname,int logs);
